/*!
* 文件名     main.c
* 作者       聚沃科技
* 版本       V1.0
* 实验简介   EXMC-外部SRAM读写实验
*/

/*
* 版权说明
* 本程序只供学习使用，未经作者许可，不得用于其它任何用途
* GD32F303东方红开发板V1
* 在线购买：   http://juwo.taobao.com
* 技术交流：   http://www.gd32bbs.com/ask/
* 视频学习：   https://space.bilibili.com/475462605
* 微信公众号： gd32bbs
* 创建日期:    2023/8/30
* Copyright    苏州聚沃电子科技有限公司
* 版权所有，盗版必究。
*/

#include "app_task.h"


#define INIT_TASK_PRIO   ( tskIDLE_PRIORITY + 1 )
#define DISPLAY_TASK_PRIO    ( tskIDLE_PRIORITY + 3 )

int wind_rise[]=
{	
    //前奏
    L7,25,M1,25,M2,25,M3,25,L3,50,M5,25,M3,25,M3,50,Z0,150, L7,25,M1,25,M2,25,M3,25,L2,50,M5,25,M3,25,M2,25,M3,25,M1,25,M2,25,L7,25,M1,25,L5,25,Z0,25, L7,25,M1,25,M2,25,M3,25,L3,50,M5,25,M3,75,Z0,150,L7,25,M1,25,M2,25,M3,25,L2,50,M5,25,M3,25,M2,25,M3,25,M1,25,M2,25,Z0,20,
    //这一路上走走停停 顺着少年漂流的痕迹
    M2,50,M2,50,M1,25,M2,50,M2,50,M1,25,M2,50,M3,50,M5,50,M3,50, M2,50,M2,50,M1,25,M2,50,M2,50,M1,25,M2,25,M3,25,M2,25,M1,25,L6,100,Z0,10,
    //迈出车站的前一刻 竟有些犹豫
    M2,50,M2,50,M1,25,M2,50,M2,50,M1,25,M2,50,M3,50,M5,50,M3,50, M2,50,M2,50,M3,25,M2,50,M1,50,M2,100,Z0,50,
    //不仅笑着这近乡情怯 仍无法避免
    M2,50,M2,50,M1,25,M2,50,M2,50,M1,25,M2,50,M3,50,M5,50,M3,50, M2,50,M2,50,M3,25,M2,50,M1,50,L6,100,Z0,10
    //而长野的天 依旧那么暖 风吹起了从前
    M3,25,M2,25,M1,25,M2,25,M1,100, M3,25,M2,25,M1,25,M2,25,M1,50,M1,50, M5,25,M3,25,M2,25,M1,25,M2,25,M1,100,M1,150,Z0,30
    //从前初识这世间 万般留恋 看着天边似在眼前 也甘愿赴汤蹈火去走它一遍
    M1,50,M2,50,M3,50,M1,50,M6,50,M5,25,M6,25,M6,50,M6,50, M1,25,M7,50,M6,25,M7,25,M7,100,Z0,5, M7,50,M6,25,M7,25,M7,50,M3,50,H1,25,H2,25,H1,25,M7,25,M6,50,M5,50, M6,50,M5,25,M6,25,M6,25,M5,25,M6,25,M5,25,M6,50,M5,25,M2,25,M2,25,M5,50,M5,50,M3,100,M3,100,Z0,25,
    //如今走过这世间 万般留恋 翻过岁月不同侧脸 措不及防闯入你的笑颜
    M1,50,M2,50,M3,50,M1,50,M6,50,M5,25,M6,25,M6,50,M6,50, M1,25,M7,50,M6,25,M7,25,M7,100,Z0,5, M7,50,M6,25,M7,25,M7,50,M3,50,H1,25,H2,25,H1,25,M7,25,M6,50,M5,50, M6,50,H3,25,H3,25,H3,50,M5,50,M6,50,H3,25,H3,25,H3,25,M5,50,M6,25,M6,100,M6,100,M6,100,Z0,25,
    //我曾难自拔于世界之大 也沉溺于其中梦话
    H1,50,H2,50,H3,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H2,25,H3,25,H3,50, H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,25,H3,50,H3,50,
    //不得真假 不做挣扎 不惧笑话
    H2,50,H1,25,M6,25,M6,25,H1,50, M6,25,H2,25,H1,25,M6,50,M6,25,H1,50,H1,50, H3,100,H3,25,H4,25,H3,50,H3,25,H2,50,H2,50,Z0,25,
    //我曾将青春翻涌成她 也曾指尖弹出盛夏 心之所动且就随缘去吧
    H1,50,H2,50,H3,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H2,50, H3,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H3,50,H3,50, H2,50,H1,25,M6,25,M6,25,H3,50,H3,50, H2,50,H1,25,M6,25,M6,25,H1,50,H1,50,H1,100,H1,100,Z0,10,
    //短短的路走走停停  也有了几分的距离
    M2,50,M2,50,M1,25,M2,50,M2,50,M1,25,M2,50,M3,50,M5,50,M3,50, M2,50,M2,50,M1,25,M2,50,M2,50,M1,25,M2,25,M3,25,M2,25,M1,25,L6,100,Z0,10,
    //不知抚摸的是故事还是段心情
    M2,50,M2,50,M1,25,M2,50,M2,50,M1,25,M2,50,M3,50,M5,50,M3,50, M2,50,M2,50,M3,25,M2,50,M1,50,M2,100,Z0,50,
    //也许期待的不过是与时间为敌
    M2,50,M2,50,M1,25,M2,50,M2,50,M1,25,M2,50,M3,50,M5,50,M3,50, M2,50,M2,50,M3,25,M2,50,M1,50,L6,100,Z0,10,
    //再次见到你 微凉晨光里 笑的很甜蜜
    M3,25,M2,25,M1,25,M2,25,M1,100, M3,25,M2,25,M1,25,M2,25,M1,50,M1,50, M5,25,M3,25,M2,25,M1,25,M2,25,M1,100,M1,150,Z0,30,
    //从前初识这世间 万般留恋 看着天边似在眼前 也甘愿赴汤蹈火去走它一遍
    M1,50,M2,50,M3,50,M1,50,M6,50,M5,25,M6,25,M6,50,M6,50, M1,25,M7,50,M6,25,M7,25,M7,100,Z0,5, M7,50,M6,25,M7,25,M7,50,M3,50,H1,25,H2,25,H1,25,M7,25,M6,50,M5,50, M6,50,M5,25,M6,25,M6,25,M5,25,M6,25,M5,25,M6,50,M5,25,M2,25,M2,25,M5,50,M5,50,M3,100,M3,100,Z0,25,
    //如今走过这世间 万般留恋 翻过岁月不同侧脸 措不及防闯入你的笑颜
    M1,50,M2,50,M3,50,M1,50,M6,50,M5,25,M6,25,M6,50,M6,50, M1,25,M7,50,M6,25,M7,25,M7,100,Z0,5, M7,50,M6,25,M7,25,M7,50,M3,50,H1,25,H2,25,H1,25,M7,25,M6,50,M5,50, M6,50,H3,25,H3,25,H3,50,M5,50,M6,50,H3,25,H3,25,H3,25,M5,50,M6,25,M6,100,M6,100,M6,100,Z0,25,
    //我曾难自拔于世界之大 也沉溺于其中梦话
    H1,50,H2,50,H3,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H2,25,H3,25,H3,50, H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,25,H3,50,H3,50,
    //不得真假 不做挣扎 不惧笑话
    H2,50,H1,25,M6,25,M6,25,H1,50, M6,25,H2,25,H1,25,M6,50,M6,25,H1,50,H1,50, H3,100,H3,25,H4,25,H3,50,H3,25,H2,50,H2,50,Z0,25,
    //我曾将青春翻涌成她 也曾指尖弹出盛夏 心之所动且就随缘去吧
    H1,50,H2,50,H3,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H2,50, H3,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H3,50,H3,50, H2,50,H1,25,M6,25,M6,25,H3,50,H3,50, H2,50,H1,25,M6,25,M6,25,H1,50,H1,50,H1,100,H1,100,Z0,10,
    //逆着光行走任风吹雨打吧
    M6,25,H3,50,H3,50,H2,50,H1,25,M6,25,M6,25,H3,50,H2,50,H1,25,M6,25,M6,25,H1,50,H1,50,H1,50,H1,100,Z0,25,
    //晚风吹起你鬓间的白发 抚平回忆留下的疤
    H1,50,H2,50,H2,25,H3,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H2,25, H3,25,H3,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,25,H3,50,H3,50,Z0,5,
    //你的眼中明暗交杂 一笑生花 暮色遮住你蹒跚的步伐
    H2,50,H1,25,M6,25,M6,25,H1,50,M6,25,H2,25,H1,25,M6,50,M6,50, H1,50,H1,50,H3,100,H3,25,H4,25,H3,50,H3,25,H2,50,H2,50,H1,100,H2,100,H3,100,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H2,50,
    //走进床头藏起的画 画中的你(低着头说话)
    H3,50,H6,25,H5,25,H5,50,H6,25,H5,25,H5,50,H6,25,H5,25,H3,100,H3,50,H2,50,H1,25,M6,25,M6,25,H3,50,H3,50,H2,50,H1,25,M6,25,M6,25,H1,100,H1,50,Z0,5,
    //我仍 了 以爱之名你还愿意吗（衔接头有问题）
    H1,50,H2,50,H1,50,H1,100,M6,25,H3,50,H3,50,H2,50,H1,25,H6,25,H6,25,H3,50,H3,50,H2,50,H1,25,H6,25,H6,25,H1,50,H1,50,H1,100,Z0,5
};
int length = sizeof(wind_rise)/sizeof(wind_rise[0]);
    

/*!
    \brief      init task
    \param[in]  pvParameters not used
    \param[out] none
    \retval     none
*/
void init_task(void * pvParameters)
{    
    driver_init();       /* 延时和公共驱动部分初始化 */
    bsp_uart_init(&BOARD_UART);      /* 打印串口初始化 */  
    
    bsp_led_group_init();        /* 初始化LED组 */
    bsp_led_on(&LED0);
    bsp_led_off(&LED1); 
    
    bsp_Rocker_ADC_config();    

    delay_ms(100);
    printf("LCD examples.\r\n");    
  
//    error_reset();
    bsp_lcd_init();                 /* 初始化LCD */
        
    /* start toogle LED2 task every 500ms */
    xTaskCreate(display_task, "display", configMINIMAL_STACK_SIZE, NULL, DISPLAY_TASK_PRIO, NULL);
    for( ;; ){
        vTaskDelete(NULL);
    }
}

/*!
* 说明     main函数
* 输入     无
* 输出     无
* 返回值   无
*/
void display_task(void * pvParameters)
{    
    uint64_t tick_temp=0;
    uint16_t frames_speed=0;    
    //计算刷整屏速度
    tick_temp=driver_tick;
    bsp_lcd_clear(WHITE);
    frames_speed=driver_tick-tick_temp;
    
    //显示log图片
    bsp_lcd_color_fill(60,0,233,99,(uint16_t*)gImage_log_picture);
    
    //设置打印窗口
    bsp_lcd_printf_init(10,109,bsp_lcd_parameter.width-1,369,FONT_ASCII_24_12,WHITE,BLUE);
    
    //打印到LCD    
    bsp_lcd_printf("GD32F303ZGT6\r\n");
    bsp_lcd_printf("EXMC LCD Brush Test\r\n");
    bsp_lcd_printf("LCD ID:%04X\r\n", bsp_lcd_parameter.id);    
    bsp_lcd_printf("* Suzhou Juwo Electronic\r\n");
    bsp_lcd_printf("* web: www.gd32bbs.com\r\n");
    bsp_lcd_printf("* B station: 475462605\r\n");
    bsp_lcd_printf("* QQ Group: 859440462\r\n");
    bsp_lcd_printf("* Taobao: juwo.taobao.com\r\n");
    bsp_lcd_printf("* Official ID: gd32bbs\r\n");        
    bsp_lcd_printf("frames brush:%d ms\r\n", frames_speed);   

    //重新设置新的打印窗口
    bsp_lcd_printf_init(0,370,bsp_lcd_parameter.width-1,bsp_lcd_parameter.height-1,FONT_ASCII_12_6,BLUE,~BLUE);

    while (1)
    {
        //将摇杆采集结果处理控制LCD亮度
        bsp_lcd_backlight_duty_set(100-(0xfff-Rocker_data[0])*100/0xfff);
        
        //打印亮度信息到LCD
        bsp_lcd_printf("* backlight is %d",100-(0xfff-Rocker_data[0])*100/0xfff); 
        bsp_lcd_printf("      ");
        //打印系统tick到LCD
        bsp_lcd_printf("* system tic is %lld \r\n",driver_tick);    
        vTaskDelay(200);                                                  
    }
}

